package com.taihe.util;

import com.sensorsdata.analytics.javasdk.SensorsAnalytics;
import com.sensorsdata.analytics.javasdk.exceptions.InvalidArgumentException;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by zwt on 2018/10/10.
 * 神策数据
 */
public class Sensorsdata {

    // 从神策分析获取的数据接收的 URL
    final static String SA_SERVER_URL = "http://tuiying.datasink.sensorsdata.cn/sa?project=default&token=edd25955ac38cd3d";
    // 使用 Debug 模式，并且导入 Debug 模式下所发送的数据
    final static boolean SA_WRITE_DATA = true;


    public static void main(String[] args) {
        // 使用 DebugConsumer 初始化 SensorsAnalytics  正式环境需要使用 .ConcurrentLoggingConsumer
        final SensorsAnalytics sa = new SensorsAnalytics(
                new SensorsAnalytics.DebugConsumer(SA_SERVER_URL, SA_WRITE_DATA));
        String distinctId = "tuiying123";
        Map<String, Object> properties = new HashMap<String, Object>();
        properties.clear();
        properties.put("$screen_name","页面名称");
        properties.put("$title","页面标题");
        try {
            sa.track(distinctId, true, "UserLogin");
            sa.track(distinctId,true,"$AppViewScreen",properties);
            sa.flush();
        } catch (InvalidArgumentException e) {
            e.printStackTrace();
        }
    }



}
